class CommonPage:
    """通用分页基类"""
    __abstract__ = True

    def __init__(self, page) -> None:
        self.current = page.page
        self.total = page.total
        self.page_size = page.per_page
        self.pages = page.pages
        self.items = page.items

    # 获取类所有属性，下划线开头的不获取
    def keys(self):
        attr = []
        for name, value in vars(self).items():
            if not name.startswith('_'):
                attr.append(name)
        return attr

    # 获取子元素属性
    def __getitem__(self, item):
        return getattr(self, item)

    # flask-json需要
    def __json__(self):
        return dict(self)
